package it.polimi.entities;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;
import java.util.List;

import it.polimi.authentication.ejb.usermanagement.*;
import it.polimi.entitiesDTO.HotelDTO;

/**
 * The persistent class for the hotel database table.
 * 
 */
@Entity
@NamedQueries ({ @NamedQuery(name=Hotel.FIND_ALL, query="SELECT h FROM Hotel h"),
				 @NamedQuery(name=Hotel.FIND_HOTEL, query="SELECT h FROM Hotel h WHERE h.name = :name"),
				 @NamedQuery(name=Hotel.FIND_BY_CITY, query="SELECT h FROM Hotel h WHERE h.city = :city"),
				 @NamedQuery(name=Hotel.FIND_BY_ID, query="SELECT h FROM Hotel h WHERE h.id = :id")

})

public class Hotel implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Hotel.findAll";
	
	public static final String FIND_HOTEL = "Hotel.findHotel";
	
	public static final String FIND_BY_CITY = "Hotel.findByCity";
	
	public static final String FIND_BY_ID = "Hotel.findByID";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	private String city;

	@Temporal(TemporalType.DATE)
	@Column(name="closure_date")
	private Date closureDate;

	private String name;

	@Temporal(TemporalType.DATE)
	@Column(name="open_date")
	private Date openDate;

	private int price;

	private int spots;

	private int stars;

	private boolean visibility;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="employee")
	private User user;

	//bi-directional many-to-one association to Packet
		@OneToMany(mappedBy="hotel")
		private List<Packet> packets;
		
		//bi-directional many-to-one association to PersonalizedPacket
		@OneToMany(mappedBy="hotel")
		private List<PersonalizedPacket> personalizedPackets;

	public Hotel() {
		super();
	}
	
	public Hotel(HotelDTO hotel){
		this.visibility = true;
		this.id = hotel.getID();
		this.name = hotel.getName();
		this.city = hotel.getCity();
		this.stars = hotel.getStars();
		this.openDate = hotel.getOpenDate();
		this.closureDate = hotel.getClosureDate();
		this.price = hotel.getPrice();
		this.spots = hotel.getSpots();
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Date getClosureDate() {
		return this.closureDate;
	}

	public void setClosureDate(Date closureDate) {
		this.closureDate = closureDate;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getOpenDate() {
		return this.openDate;
	}

	public void setOpenDate(Date openDate) {
		this.openDate = openDate;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getSpots() {
		return this.spots;
	}

	public void setSpots(int spots) {
		this.spots = spots;
	}

	public int getStars() {
		return this.stars;
	}

	public void setStars(int stars) {
		this.stars = stars;
	}

	public boolean getVisibility() {
		return this.visibility;
	}

	public void setVisibility(boolean visibility) {
		this.visibility = visibility;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<PersonalizedPacket> getPersonalizedPackets() {
		return this.personalizedPackets;
	}

	public void setPersonalizedPackets(List<PersonalizedPacket> personalizedPackets) {
		this.personalizedPackets = personalizedPackets;
	}
	
	public String toString (){
		
		return "ID: " + this.getId() + " City: " + this.getCity() + " Stars: " + this.getStars()+ "open date"+ this.getOpenDate().toString()+"closure date"+this.getClosureDate().toString();
		}

}